#include "StdAfx.h"
#include "ProteinVista.h"

#include "ProteinVistaDoc.h"
#include "ProteinVistaView.h"
#include "PDBRenderer.h"
#include "ProteinVistaRenderer.h"
#include "EasyAccessFunction.h"

#include "RenderObjectSelection.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

HRESULT CRenderObjectSelection::RenderPovRayPreCommonBlock(CString &strPovRay, CStdioFile & file)
{
	return S_OK;
}

HRESULT CRenderObjectSelection::RenderPovRayPostCommonBlock(CString &strPovRay, CStdioFile & file)
{
	//	clip plane
	strPovRay += _T("difference {\r\n");
	strPovRay += _T("\tdifference {\r\n");
	strPovRay += _T("\t\tdifference{ \r\n");
	strPovRay += _T("\t\t\tobject { mesh_object } \r\n");      
	if ( m_pPropertyCommon->m_bClipping1 == TRUE )
	{
		if ( m_pPropertyCommon->m_bClipDirection1 == TRUE ) { m_pPropertyCommon->m_clipPlaneEquation1 *= -1;  }
		if ( m_pPropertyCommon->m_bShowClipPlane1 == TRUE )
		{
			strPovRay.AppendFormat(_T("\t\t\tplane{ <%f,%f,%f>, %f pigment { rgbt<%f,%f,%f,%f> } } \r\n"), 
										-m_pPropertyCommon->m_clipPlaneEquation1.a, 
										-m_pPropertyCommon->m_clipPlaneEquation1.b, 
										-m_pPropertyCommon->m_clipPlaneEquation1.c, 
										m_pPropertyCommon->m_clipPlaneEquation1.d ,
										GetRValue(m_pPropertyCommon->m_clipPlaneColor1)/255.0f, GetGValue(m_pPropertyCommon->m_clipPlaneColor1)/255.0f, GetBValue(m_pPropertyCommon->m_clipPlaneColor1)/255.0f, 1-m_pPropertyCommon->m_clipPlaneTransparency1/255.0f );
		}
		else
		{
			strPovRay.AppendFormat(_T("\t\t\tclipped_by { plane{ <%f,%f,%f>, %f } } \r\n"), 
										m_pPropertyCommon->m_clipPlaneEquation1.a, 
										m_pPropertyCommon->m_clipPlaneEquation1.b, 
										m_pPropertyCommon->m_clipPlaneEquation1.c, 
										-m_pPropertyCommon->m_clipPlaneEquation1.d );
		}
		if ( m_pPropertyCommon->m_bClipDirection1 == TRUE ) { m_pPropertyCommon->m_clipPlaneEquation1 *= -1;  }
	}
	strPovRay += _T("\t\t} \r\n");
	if ( m_pPropertyCommon->m_bClipping2 == TRUE )
	{
		if ( m_pPropertyCommon->m_bClipDirection2 == TRUE ) m_pPropertyCommon->m_clipPlaneEquation2 *= -1;
		if ( m_pPropertyCommon->m_bShowClipPlane2 == TRUE )
		{
			strPovRay.AppendFormat(_T("\t\tplane{ <%f,%f,%f>, %f pigment { rgbt<%f,%f,%f,%f> } } \r\n"),
										-m_pPropertyCommon->m_clipPlaneEquation2.a, 
										-m_pPropertyCommon->m_clipPlaneEquation2.b, 
										-m_pPropertyCommon->m_clipPlaneEquation2.c, 
										m_pPropertyCommon->m_clipPlaneEquation2.d ,
										GetRValue(m_pPropertyCommon->m_clipPlaneColor2)/255.0f, GetGValue(m_pPropertyCommon->m_clipPlaneColor2)/255.0f, GetBValue(m_pPropertyCommon->m_clipPlaneColor2)/255.0f, 1-m_pPropertyCommon->m_clipPlaneTransparency2/255.0f );
		}
		else
		{
			strPovRay.AppendFormat(_T("\t\tclipped_by { plane{ <%f,%f,%f>, %f } } \r\n"), 
										m_pPropertyCommon->m_clipPlaneEquation2.a, 
										m_pPropertyCommon->m_clipPlaneEquation2.b, 
										m_pPropertyCommon->m_clipPlaneEquation2.c, 
										-m_pPropertyCommon->m_clipPlaneEquation2.d );
		}
		if ( m_pPropertyCommon->m_bClipDirection2 == TRUE ) m_pPropertyCommon->m_clipPlaneEquation2 *= -1;
	}
	strPovRay += _T("\t} \r\n");
	if ( m_pProteinVistaRenderer->m_pPropertyScene->m_bClipping0 == TRUE )
	{
		if ( m_pProteinVistaRenderer->m_pPropertyScene->m_bClipDirection0 == TRUE )		m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0 *= -1;
		if ( m_pProteinVistaRenderer->m_pPropertyScene->m_bShowClipPlane0 == TRUE )
		{
			strPovRay.AppendFormat(_T("\tplane{ <%f,%f,%f>, %f pigment { rgbt<%f,%f,%f,%f> } } \r\n"), 
										-m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.a, 
										-m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.b, 
										-m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.c, 
										m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.d ,
										GetRValue(m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneColor0)/255.0f, GetGValue(m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneColor0)/255.0f, GetBValue(m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneColor0)/255.0f, 1-m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneTransparency0/255.0f );
		}
		else
		{
			strPovRay.AppendFormat(_T("\tclipped_by { plane{<%f,%f,%f>, %f}  } \r\n"), 
										m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.a, 
										m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.b, 
										m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.c, 
										-m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0.d );
		}
		if ( m_pProteinVistaRenderer->m_pPropertyScene->m_bClipDirection0 == TRUE )		m_pProteinVistaRenderer->m_pPropertyScene->m_clipPlaneEquation0 *= -1;
	}
	strPovRay += _T("} \r\n");

	return S_OK;
}

